package com.tianzhu.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tianzhu.domain.Customer;
import com.tianzhu.service.CustomerService;
import com.tianzhu.util.ApplicationUtils;

@Controller
@RequestMapping("/customer/cart")
public class CartController {

    @Autowired
    private CustomerService customerService;

    @RequestMapping
    public String getCart(){
    	
        Customer customer = customerService.getCustomerByUsername(ApplicationUtils.getUser().getUsername());
        Long cartId = customer.getCart().getCartid();

        return "redirect:/customer/cart/" + cartId;
    }

    @RequestMapping("/{cartId}")
    public String getCartRedirect(@PathVariable (value = "cartId") Long cartId, Model model){
        model.addAttribute("cartId", cartId);

        return "pages/cart";
    }

} // The End of Class;
